/**
 * @Copyright (C) 2018 本内容属于商业秘密，易微行(北京)科技有限公司拥有版权等所有权利.
 */
package com.xxy.orders.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xxy.microservice.common.page.PageList;
import com.xxy.orders.dto.AppOrderDTO;
import com.xxy.orders.entity.AppOrder;
import com.xxy.orders.entity.AppOrderExample;
import com.xxy.orders.entity.mapper.AppOrderMapper;
import com.xxy.orders.rabitmq.RabbitMQSender;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * xuxy
 * 2018/2/8
 */
@Service
public class AppOrderServcieImpl implements AppOrderService{
    @Autowired
    AppOrderMapper mapper;

    @Autowired
    RabbitMQSender sender;
    @Override
    public List<AppOrderDTO> findAll() {
        sender.topicSender("有人查询订单列表了!!!");
        AppOrderExample example = new AppOrderExample();
        AppOrderExample.Criteria criteria = example.createCriteria();
        criteria.andOrderIdEqualTo(2781L);
        List<AppOrder> appOrders = mapper.selectByExample(example);
        List<AppOrderDTO> result = new ArrayList();
        for (AppOrder appOrder : appOrders) {
            AppOrderDTO appOrderDTO = new AppOrderDTO();
            BeanUtils.copyProperties(appOrder, appOrderDTO);
            result.add(appOrderDTO);
        }
        return result;
    }


    @Override
    public PageList<AppOrderDTO> listPage(AppOrderDTO dto, PageList page){
        AppOrderExample example = new AppOrderExample();
        AppOrderExample.Criteria criteria = example.createCriteria();
        criteria.andStatusEqualTo("7");
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        List<AppOrder> appOrders = mapper.selectByExample(example);
        List<AppOrderDTO> result = new ArrayList();
        for (AppOrder appOrder : appOrders) {
            AppOrderDTO appOrderDTO = new AppOrderDTO();
            BeanUtils.copyProperties(appOrder, appOrderDTO);
            result.add(appOrderDTO);
        }
        return new PageList<AppOrderDTO>(result, (Page)appOrders);
    }
}
